<?php
Loader::loadFile('config.php', "modules/IShopStore");
Loader::loadClass('PNObjectExArray', "modules/IShopStore/pnincludes");
Loader::loadClass('InnoUtil', "modules/IShopStore/pnincludes");
Loader::loadClass('DBUtilEx', "modules/IShopStore/pnincludes");


/**
 * initialise block
 * 
 * @author       The PostNuke Development Team
 */
function IShopStore_CategoriesMenublock_init()
{

}

/**
 * get information on block
 * 
 * @return       array       The block information
 */
function IShopStore_CategoriesMenublock_info()
{
    return array('text_type'      => 'Categories menu',
                 'module'         => 'IShopStore',
                 'text_type_long' => 'Show Categories menu',
                 'allow_multiple' => true,
                 'form_content'   => false,
                 'form_refresh'   => false,
                 'show_preview'   => true);
}

/**
 * display block
 * 
 * @author       The PostNuke Development Team
 * @param        array       $blockinfo     a blockinfo structure
 * @return       output      the rendered bock
 */
function IShopStore_CategoriesMenublock_display($blockinfo)
{

    if (!SecurityUtil::checkPermission('IShopStore:CategoriesMenublock:', "$blockinfo[title]::", ACCESS_READ)) {
        return false;
    }
    
    $modname  = 'IShopStore';
    $class    = 'Categories';
    $vars = pnBlockVarsFromContent($blockinfo['content']);
    $modinfo = pnModGetInfo(pnModGetIDFromName($modname));
    $directory = $modinfo['directory'];
    pnModDBInfoLoad($modname, $directory);

    //check module if login is display then not show again.
    //$module = FormUtil::getPassedValue ('module', false , 'GET');
    //$func = FormUtil::getPassedValue ('func', false , 'GET');
    $module = 'IShopStore';
    $func =   'view';
    if ($module == 'Users' && $func == 'loginscreen'){
      $blockinfo['content'] = null;
      return themesideblock($blockinfo);
    }

    //load render
    $render = pnRender::getInstance($modname);
    //load class
    if (!($class = Loader::loadClassFromModule ('IShopStore', $class, true)))
      return LogUtil::registerError ("Unable to load class [$class] ...");


    //pagnigation variable
    $filter  = FormUtil::getPassedValue ('filter', 0);
    $offset  = FormUtil::getPassedValue ('startnum', 0);
    $sort    = FormUtil::getPassedValue ('sort', '');
    $pagesize = pnModGetVar ('IShopStore', 'pagesize') ? pnModGetVar ('IShopStore', 'pagesize') : 100;

    $render = pnRender::getInstance('IShopStore');
    $render->assign('is_loggedin' , pnUserLoggedIn());
    $render->assign('user',   InnoUtil::getUserInfo());


    $objectArray = new $class ();
    $where   = null;
    $sort = null;
    if (method_exists($objectArray,'genFilter')){
      $where = $objectArray->genFilter();
    }
    if (method_exists($objectArray,'genSort')){
      $sort = $objectArray->genSort();
    }
    if (method_exists($objectArray,'selectExtendResult')){
      $resultex = $objectArray->selectExtendResult();
      $render->assign('extendResult', $resultex);
    }

    $objectArray->get ($where, $sort , $offset, 10);
    //var_dump($objectArray); exit;
    //assign to view
    $render->assign('objectArray', $objectArray->_objData);

    $render->assign('ctrl', $ctrl);

    // Populate block info and pass to theme
    $blockinfo['content'] = $render->fetch('user_block_categoriesmenu.htm');
    return themesideblock($blockinfo);

}
